/*
 * Copyright (C) 2021 HERE Europe B.V.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * License-Filename: LICENSE
 */

class VulnerabilityReference {
    #scoringSystem;

    #severity;

    #severityIndex;

    #severityMapped;

    #url;

    constructor(obj) {
        if (obj instanceof Object) {
            if (obj.scoring_system !== null || obj.scoringSystem) {
                this.#scoringSystem = obj.scoring_system || obj.cscoringSystem;
            }

            if (obj.severity !== null) {
                this.#severity = obj.severity;
            }

            if (obj.severity_mapped !== null || obj.severityMapped !== null) {
                this.#severityMapped = obj.severity_mapped || obj.severityMapped;

                switch (this.#severityMapped) {
                    case 'CRITICAL':
                        this.#severityIndex = 0;
                        break;
                    case 'HIGH':
                        this.#severityIndex = 1;
                        break;
                    case 'MEDIUM':
                        this.#severityIndex = 2;
                        break;
                    case 'LOW':
                        this.#severityIndex = 3;
                        break;
                    default:
                        this.#severityIndex = 4;
                }
            }

            if (obj.url !== null) {
                this.#url= obj.url;
            }
        }
    }

    get scoringSystem () {
        return this.#scoringSystem;
    }

    get severity() {
        return this.#severity;
    }

    get severityIndex() {
        return this.#severityIndex;
    }

    get severityMapped() {
        return this.#severityMapped;
    }

    get url() {
        return this.#url;
    }
}

export default VulnerabilityReference;
